package com.blrs.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.blrs.service.collection.IIndexCollectionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.IndexCollection;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 首页收藏夹Controller
 * 
 * @author xiaoyang
 * @date 2024-07-31
 */
@RestController
@RequestMapping("/collection/collection")
public class IndexCollectionController extends BaseController
{
    @Autowired
    private IIndexCollectionService indexCollectionService;

    /**
     * 查询首页收藏夹列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IndexCollection indexCollection)
    {
        startPage();
        List<IndexCollection> list = indexCollectionService.selectIndexCollectionList(indexCollection);
        return getDataTable(list);
    }





    /**
     * 导出首页收藏夹列表
     */
    @Log(title = "首页收藏夹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IndexCollection indexCollection)
    {
        List<IndexCollection> list = indexCollectionService.selectIndexCollectionList(indexCollection);
        ExcelUtil<IndexCollection> util = new ExcelUtil<IndexCollection>(IndexCollection.class);
        util.exportExcel(response, list, "首页收藏夹数据");
    }

    /**
     * 获取首页收藏夹详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(indexCollectionService.selectIndexCollectionById(id));
    }

    /**
     * 新增首页收藏夹
     */
    @Log(title = "首页收藏夹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndexCollection indexCollection)
    {
        return toAjax(indexCollectionService.insertIndexCollection(indexCollection));
    }

    /**
     * 修改首页收藏夹
     */
    @Log(title = "首页收藏夹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndexCollection indexCollection)
    {
        return toAjax(indexCollectionService.updateIndexCollection(indexCollection));
    }

    /**
     * 删除首页收藏夹
     */
    @Log(title = "首页收藏夹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(indexCollectionService.deleteIndexCollectionByIds(ids));
    }
}
